/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.powerhua.workflow.utils;

import com.powerhua.workflow.jbpm.deploy.JbpmDeploy;
import com.powerhua.workflow.jbpm.deploy.impl.JbpmDeployImpl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jbpm.JbpmConfiguration;
import org.jbpm.persistence.db.DbPersistenceServiceFactory;
import org.jbpm.svc.Services;

/**
 *
 * @author Brian.Xie
 */
public class DeployUtils {

    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
    DbPersistenceServiceFactory dbPersistenceServiceFactory =
            (DbPersistenceServiceFactory) jbpmConfiguration.getServiceFactory(Services.SERVICENAME_PERSISTENCE);

    public static void main(String[] args) {
        DeployUtils dp = new DeployUtils();
        //dp.createSchema();
        dp.deploy();
    //dp.dropSchema();
    }

    public void createSchema() {
        dbPersistenceServiceFactory.createSchema();
    }

    public void deploy() {
        JbpmDeploy jbpmDeploy = new JbpmDeployImpl();
        File f = new File("D:/Brian/dev/project/xsys_workflow/src/jpdl/demo.zip");
        FileInputStream in;
        try {
            in = new FileInputStream(f);
            jbpmDeploy.deploy(in);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(DeployUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void dropSchema() {
        dbPersistenceServiceFactory.dropSchema();
    }
}
